package com.rasenhund.android.gsimulator.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.rasenhund.android.gsimulator.R;
import com.rasenhund.android.gsimulator.common.Const;
import com.rasenhund.android.gsimulator.schema.MobileSuit;

/**
 * MS選択 ListAdapter
 */
public class MsListAdapter extends ArrayAdapter<MobileSuit> {

    private List<MobileSuit> items;
    private LayoutInflater mInflater;
    
    private Context mContext;
    
    public MsListAdapter(Context context, List<MobileSuit> objects) {
        super(context, 0, objects);

        mContext = context;

        mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        items = objects;
        
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view;

        if (convertView != null) {
            view = convertView;
        } else {
            view = mInflater.inflate(R.layout.select_ms_row, null);
        }

        MobileSuit item = (MobileSuit) getItem(position);

        if (item != null) { 
            
            // カテゴリ名
            TextView txtCategory = (TextView)
                    view.findViewById(R.id.txtCategory);

            switch (item.getCategoryCd()) {
                case Const.CATEGORY.GRAPP:
                    txtCategory.setText(mContext.getString(R.string.category_grapp));
                    txtCategory.setBackgroundResource(R.drawable.category_grapp);
                    break;
                case Const.CATEGORY.SHORT:
                    txtCategory.setText(mContext.getString(R.string.category_short));
                    txtCategory.setBackgroundResource(R.drawable.category_short);
                    break;
                case Const.CATEGORY.SHOOT:
                    txtCategory.setText(mContext.getString(R.string.category_shoot));
                    txtCategory.setBackgroundResource(R.drawable.category_shoot);
                    break;
                case Const.CATEGORY.TANK:
                    txtCategory.setText(mContext.getString(R.string.category_tank));
                    txtCategory.setBackgroundResource(R.drawable.category_tank);
                    break;
                case Const.CATEGORY.SNIPE:
                    txtCategory.setText(mContext.getString(R.string.category_snipe));
                    txtCategory.setBackgroundResource(R.drawable.category_snipe);
                    break;
                default:
                    break;
            }

            // 型番
            TextView txtModelNo = (TextView)
                    view.findViewById(R.id.txtModelNo);
            txtModelNo.setText(item.getModelNo());

            // MS名称
            TextView txtMsName = (TextView)
                    view.findViewById(R.id.txtMsName);
            txtMsName.setText(item.getMsNameShort(12));

            // コスト
            TextView txtCost = (TextView) view.findViewById(R.id.txtCost);
            txtCost.setText(String.valueOf(item.getCost()));

        }

        return view;

    }
    
    @Override
    public MobileSuit getItem(int position) {
        return items.get(position);
    }

    /********************
     * EventListener
     ********************/

    /********************
     * Method
     ********************/
        
}
